import {
  SUB_PAGES
} from "../../config/router.config";
import {
  createStoreBindings
} from "mobx-miniprogram-bindings";
import {
  callLogsFilterStore
} from "../../store/callLogsFilterStore";
import {
  deptSelectStore
} from "../../store/deptSelectStore";

import {
  handleDelChecked,
  handleFilterRouter
} from "../../utils/util";
import {
  userSelectStore
} from "../../store/userSelectStore";
import {
  CallLogsApi
} from "../../common/apis/callLogs";
const mixin_dicKey = require('../../common/mixins/dicKey')

Page({
  behaviors: [mixin_dicKey],

  /**
   * 页面的初始数据
   */
  data: {

  },
  // 获取坐席人员数据
  geSeatman() {
    const self = this

    CallLogsApi.getServerUser((res) => {
      self.setServerUserList(res.data)

    })
  },
  onFilterDept() {
    const toUrl = `${SUB_PAGES.Filter.FILTER_DEPT_SELECT.router}?${handleFilterRouter(SUB_PAGES.CallLogs.FILTER.router, 'selectDept', )}`
    wx.navigateTo({
      url: toUrl
    })
  },
  // 人员筛选
  onFilterUser() {
    const toUrl = `${SUB_PAGES.Filter.FILTER_USER_SELECT.router}?${handleFilterRouter(SUB_PAGES.CallLogs.FILTER.router, )}`
    wx.navigateTo({
      url: toUrl
    })
  },
  onDelDeptData(event) {
    const {
      value
    } = event.currentTarget.dataset
    const data = handleDelChecked(value, this.data.choseDeptValue, "value")
    this.delDeptData(data)

  },
  onDelUserData(event) {
    const {
      value
    } = event.currentTarget.dataset
    const data = handleDelChecked(value, this.data.choseUserData, "id")
    this.setUserSelectStore(data)
  },
  onSubmit() {
    this.setDeptIdList(this.data.choseDeptValue)
    this.setReceptionList(this.data.choseUserData)
    wx.redirectTo({
      url: SUB_PAGES.CallLogs.INDEX.router,
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.storeBindings = createStoreBindings(this, {
      store: callLogsFilterStore,
      fields: ["dealType", "deptIdList", "endTime", "receptionList", "startTime", "type", "serverUserList"],
      actions: ["onTag", "onChangeTime", "setDeptIdList", "setReceptionList", "setServerUserList"],
    })
    this.storeBindings1 = createStoreBindings(this, {
      store: deptSelectStore,
      fields: ["choseDeptValue"],
      actions: ["delDeptData"]
    })
    this.storeBindings2 = createStoreBindings(this, {
      store: userSelectStore,
      fields: ["choseUserData"],
      actions: ["setUserSelectStore"]
    })
    this.storeBindings.updateStoreBindings()
    this.storeBindings1.updateStoreBindings()
    this.storeBindings2.updateStoreBindings()
    this.geSeatman()

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    this.storeBindings.destroyStoreBindings();
    this.storeBindings1.destroyStoreBindings()
    this.storeBindings2.destroyStoreBindings()
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})